<template>
  <div class="risk">
    <van-search
      @search="onSearch"
      @clear="clearSearch"
      class="info_search input_text"
      v-model="value"
      placeholder="搜索"
    />
    <van-list
      :finished="finished"
      v-model="loading"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell class="card" v-for="(item, index) in list" :key="index">
        <van-tag v-if="item.Status != 14" class="info_tag" type="normal"
          >进行中</van-tag
        >
        <van-tag v-if="item.Status == 14" class="info_tag" type="warning"
          >已退场</van-tag
        >
        <div class="warn_item">
          <div @click="detail(item)">
            <div class="warn_header f16">
              <div>项目名称：{{ item.ProjectName }}</div>
            </div>
            <div class="dep_sort">
              <div>施工类型：{{ item.ProjectTypeName }}</div>
            </div>
            <div class="dep_sort">
              <div>施工方负责人：{{ item.ManagerProject }}</div>
            </div>
            <div class="dep_sort">
              <div>联系方式：{{ item.ManagerProjectTel }}</div>
            </div>
            <div class="dep_sort">
              <div>
                施工日期：{{ item.ProjectStart | formatDate }}至{{
                  item.ProjectEnd | formatDate
                }}
              </div>
            </div>
          </div>
          <div class="dep_btm" v-if="item.AllowCanJoinTrainPlan">
            <div class="btm_item" @click="toTrainPlanDetail(item)">
              <img src="@/assets/Images/AppIcon/icon_list_edit.png" />
              <div class="mr-10">加入培训</div>
            </div>
          </div>
          <div class="dep_btm" v-if="item.AllowCanStudyTrainPlan">
            <div
              class="cert"
              v-if="item.PermitImg != null && item.PermitImg != ''"
              @click="showImage(item.PermitImg)"
            >
              施工通行证
            </div>
            <div class="btm_item" @click="toTrainPlanDetail(item)">
              <img src="@/assets/Images/AppIcon/icon_list_edit.png" />
              <div class="mr-10">培训学习</div>
            </div>
          </div>
        </div>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import { getPageData, join } from "@/api/constructSafeProject";
import { mapGetters } from "vuex";
import { ImagePreview } from "vant";
export default {
  props: {},
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      value: "",
      list: [],
      filter: {
        page: 0,
        dataType: "ListProject",
      },
      loading: false,
      finished: false,
    };
  },
  created() {
    this.getList();
  },
  computed: {
    ...mapGetters(["roles"]),
  },
  methods: {
    onSearch() {
      var conditions = [];
      if (this.value) {
        conditions.push({
          Name: "Keywords",
          DisplayName: this.value,
          Value: this.value,
          Operator: "like",
          DataType: "String",
          IsTemp: false,
        });
      }
      this.filter.page = 0;
      this.filter.conditions = JSON.stringify(conditions);
      this.getList();
    },
    detail(item) {
      //  this.$router.push({
      //     path: "ConstructSafeProjectView",
      //     query: { id: item.ID },
      //   });
    },
    clearSearch() {
      this.filter = {
        page: 0,
        dataType: "ListProject",
      };
      this.value = "";
      this.getList();
    },
    getList() {
      this.loading = true;
      getPageData(this.filter).then((res) => {
        this.loading = false;
        if (!res.data.HasNextPage) {
          this.finished = true;
        }
        this.list = res.data.Data;
        this.filter.page = res.data.PageIndex;
      });
    },
    onLoad() {
      this.loading = true;
      ++this.filter.page;
      list(this.filter).then((res) => {
        this.loading = false;
        this.filter.page = res.data.PageIndex;
        this.list = this.list.concat(res.data.Data);
        if (!res.data.HasNextPage) {
          this.finished = true;
        }
      });
    },
    toTrainPlanDetail(item) {
      this.$router.push("/Train/TrainingplanDetail?id=" + item.PlanID);
    },

    showImage(url) {
      ImagePreview({
        images: [this.baseUrl + url],
      });
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.all_dep {
  background-color: #ffffff;
}
.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
  .warn_tag {
    position: absolute;
    right: -10px;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}
.dep_sort {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.warn_item {
  .van-radio {
    position: absolute;
    right: 10px;
    top: 41px;
  }
}
.dep_btm {
  display: flex;
  justify-content: flex-end;
  line-height: 27px;
  .cert {
    cursor: pointer;
    color: #1989fa;
    margin-right: 10px;
  }

  .btm_item {
    display: flex;
    align-items: center;
    cursor: pointer;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}

</style>
